/*
Copyright 2010 Sieric
http://sieric.ca

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package vanilla;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class Section_Local extends JComponent implements Section, ActionListener {
	private JTextField directoryName;
	
	public Section_Local() {
		JLabel tmp = new JLabel("Local: ");
		tmp.setBounds(1, 1, 80, 20);
		add(tmp);
		
		directoryName = new JTextField();
		directoryName.setBounds(80, 1, 300, 20);
		add(directoryName);
		
		JButton browse = new JButton("Browse");
		browse.setActionCommand("browse");
		browse.addActionListener(this);
		browse.setBounds(390, 1, 80, 20);
		add(browse);
	}
	
	public String getConfig() {
		return "local|" + directoryName.getText().replace('\\', '/');
	}

	// The only the browse button
	public void actionPerformed(ActionEvent arg0) {
		JFileChooser fc = new JFileChooser(directoryName.getText());
		fc.setDialogTitle("Choose a directory");
		fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
			directoryName.setText(fc.getSelectedFile().getAbsolutePath().replace('\\', '/'));
			
		}
	}

	public int getBigHeight() {
		return 20;
	}

}
